//
//  HpProduct_Item_H_CCell.swift
//  Pods
//
//  Created by eme on 2017/3/27.
//
//

import UIKit
import UtilCore
import BrandonCore

class HpProduct_Item_H_CCell: UICollectionViewCell {
    
    static let interitemSpacing:CGFloat = 0
    static let lineSpacing:CGFloat = 10
    static let cellTop:CGFloat = 10
    static let cellBottom:CGFloat = 10
    static let cellLeft:CGFloat = 5
    static let cellRight:CGFloat = 5
    static var cellSize:CGSize{
        get{
            let width:CGFloat = 258 * screen_Width/750
            let height:CGFloat = ceil((442 - 20 - 20) * screen_Width/750)
            return CGSize(width: width, height: height)
        }
    }
    static var cellEdgeInsets:UIEdgeInsets{
        get{
            return  UIEdgeInsets(top: HpProduct_Item_H_CCell.cellTop, left: HpProduct_Item_H_CCell.cellLeft, bottom: HpProduct_Item_H_CCell.cellBottom, right: HpProduct_Item_H_CCell.cellRight)
        }
    }
    
    //商品名称
    @IBOutlet weak var pdname_Lb: UILabel!
    //店铺进货价
    @IBOutlet weak var shprice_Lb: UILabel!
    
    @IBOutlet weak var jinPriceImg_V: UIImageView!
    //  利润
    @IBOutlet weak var profit_V: UIView!
    @IBOutlet weak var profit_Lb: UILabel!
    /// 显示已售罄
    @IBOutlet weak var sellOut_ImgV: UIImageView!
    @IBOutlet weak var img1_ImgV: UIImageView!
    var item :HpProductModel?{
        didSet{
            if let item = self.item {
                self.pdname_Lb.text = item.pdname
                self.img1_ImgV.setUrlImage(item.img1)
                self.profit_Lb.text = item.profit.getFormatStr()
                
                self.jinPriceImg_V.image = UIImage(named: AppData.getPriceImgName(), in: RobbCore.bundle, compatibleWith: nil)
                self.shprice_Lb.text = AppData.getFinalShowPrice(jinPrice: item.minshprice, lingPrice: item.bdprice).getPriceStr()
                if item.stock == 0 || item.pdstate != "3" {
                    self.sellOut_ImgV.isHidden = false
                    self.sellOut_ImgV.image = UIImage(named: item.stock == 0 ?"sellout":"failure", in: RobbCore.bundle, compatibleWith: nil)
                }else{
                    self.sellOut_ImgV.isHidden = true
                }
                if  case .audited = AppData.appState {
                    self.profit_V.isHidden = false
                    /// 1 表示商品 0 表示是仪器等非商品类型
                    self.profit_V.isHidden = item.ptisproduct != "1"
                }else{
                    self.profit_V.isHidden = true
                }
            }
        }
    }
    override func awakeFromNib() {
        self.pdname_Lb.normal_fontSize(12)
        self.shprice_Lb.bold_fontSize(13)
    }
}
